package com.axend.aerosense.common.ui;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;

import com.axend.aerosense.common.R;
import com.axend.aerosense.common.databinding.CommonVipRenewNoticeDialogBinding;

import static com.blankj.utilcode.util.StringUtils.getString;

public class CustomVipRenewDialog extends Dialog {
    private CommonVipRenewNoticeDialogBinding databinding;
    private String days;
    public CustomVipRenewDialog(@NonNull Context context,String days) {
        super(context, R.style.Common_CustomDialog);
        this.days = days;
        databinding = DataBindingUtil.inflate(getLayoutInflater(),R.layout.common_vip_renew_notice_dialog,null,false);
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        //提示框位置设置
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.CENTER;
        window.setAttributes(lp);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(databinding.getRoot());
        //按空白处不能取消
        setCanceledOnTouchOutside(false);
        initView();
        initEvent();
    }

    /**
     * 初始界面
     */
    private void initView(){
        //设置过期剩余天数
        databinding.commonTv.setText(String.format(getString(R.string.common_vip_renew_notice),days));
    }

    /**
     * 初始化事件
     */
    private void  initEvent(){
        databinding.commonButOk.setOnClickListener( v -> {
            dismiss();
        });
        databinding.commonImgClose.setOnClickListener(v->{
            dismiss();
        });
    }

}
